import Vue from 'vue'
import VueRouter from 'vue-router'


Vue.use(VueRouter)

const routes = [
  {
    path: '/index',
    name: 'index',
    meta: { title: "index" },
    component: () => import('../views/Index.vue'),
    children: [
      {
        path: '/index/home',
        name: 'home',
        meta: { title: "首页" },
        component: () => import('../views/Index/Home.vue')
      },
      {
        path: '/index/tuan',
        name: 'tuan',
        meta: { title: "爆爆团" },
        component: () => import('../views/Index/Tuan.vue')
      },
      {
        path: '/index/order',
        name: 'order',
        meta: { title: "订单" },
        component: () => import('../views/Index/Order.vue')
      },
      ,
      {
        path: '/index/mine',
        name: 'mine',
        meta: { title: "我的" },
        component: () => import('../views/Index/Mine.vue')
      },
      //搜索框路由
      {
        path: '/index/search',
        name: 'search',
        meta: { title: "搜索" },
        component: () => import('../views/Index/Search.vue')
      },
      // 搜索结果页
      {
        path: '/index/searchResult',
        name: 'searchResult',
        meta: { title: "搜索结果" },
        component: () => import('../views/Index/SearchResult.vue')
      },
      {
        path: '/index',
        redirect: '/index/home'
      },
      {
        path: '*',
        component: () => import('../views/Notfound.vue'),
      }
    ]
  },
  {
    path: '/login',
    name: 'login',
    meta: { title: "登录" },
    component: () => import('../views/Login.vue'),
  },
  {
    path: '/register',
    name: 'register',
    meta: { title: "注册" },
    component: () => import('../views/Register.vue'),
  },
  {
    path: '/details/:id',
    name: 'details',
    meta: { title: "店铺详情" },
    component: () => import('../views/Details.vue'),
  },
  {
    path: '/',
    redirect: '/index'
  },
  {
    path: '*',
    component: () => import('../views/Notfound.vue'),
  }

]
const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {
  //to是去到新的路由
  document.title = to.meta.title;
  next()
})

export default router
